﻿using System.Threading.Tasks;
using Competition.Application.DTO;
using Competition.Application.Interfaces;
using Competition.Domain;
using Competition.Domain.Entity;
using MiDu.Common;

namespace Competition.Application
{
    public class PlatformMemberService:BaseService<PlatformMember>, IPlatformMemberService
    {
        public PlatformMemberService(AppDbContext dbContext) : base(dbContext)
        {
        }
        /// <summary>
        /// 查询用户
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <param name="password">密码</param>
        /// <returns>不存在为null</returns>
        public async Task<PlatformMemberDto> FindAsync(string userName, string password)
        {
            password = DEncryptHelper.MD5Encrypt(password);
            var model = await this.GetService<PlatformMember>().FindAsync(awm => awm.UserName == userName && awm.Password == password);
            if (model != null)
            {
                PlatformMemberDto dto = new PlatformMemberDto()
                {
                    Id = model.Id,
                    Nickname = model.Nickname
                };
                return dto;
            }

            return null;
        }
    }
}